#include <stdlib.h>
#include <omp.h>
#include <stdio.h>
//#define NUM_THREADS 16
//编译指令
//gcc -std=c99 -fopenmp 2HelloWorld.c -o cmake-build/2HelloWorld && export OMP_NUM_THREADS=512 && time ./cmake-build/2HelloWorld

int main()
{
    static long num_steps=1000000000;
    double      step;
    int         i;
    double      x,pi,sum =0.0;
    step=1.0/(double)num_steps;
    //omp_set_num_threads(NUM_THREADS);
    
#pragma omp parallel for reduction(+:sum) private(x) shared(num_steps,step) default(none)
    for(i=0;i<num_steps;i++)
    {
        x=(i+0.5)*step;
        sum+=4.0/(1.0+x*x);
    }
    pi=step*sum;
    printf("Pi=%21.20f(%ld steps)\n",pi,num_steps);
    return 0;
}
